package com.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.util.Arrays;

import com.acrm.client.entity.staff.Staff;
import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;

public class HessianDemo {
	public static void main(String[] args) throws IOException {
		SoftReference sr;
		Staff s=new Staff();
		s.setStaffCD("guxuede");
		s.setLevel(100);
		
		readObject_Hessian(writeObject_Hessian(s));
		//writeObject_JDK(s);
	}
	
	public static InputStream writeObject_Hessian(Serializable obj) throws IOException{
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		Hessian2Output out=new Hessian2Output(bos);
		out.writeObject(obj);
		out.flushBuffer();
		System.out.println(bos.size()+","+Arrays.toString(bos.toByteArray()));
		return new ByteArrayInputStream(bos.toByteArray());
	}
	
	public static void readObject_Hessian(InputStream in) throws IOException{
		Hessian2Input hin=new Hessian2Input(in);
		Object o=hin.readObject();
		System.out.println(o);
	}
	
	public static void writeObject_JDK(Serializable obj) throws IOException{
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		ObjectOutputStream out=new ObjectOutputStream(bos);
		out.writeObject(obj);
		out.flush();
		System.out.println(bos.size()+","+Arrays.toString(bos.toByteArray()));
	}
}
